package com.fz.service;

import com.fz.entity.Book;
import com.fz.mapper.BookMapper;
import com.fz.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

/**
 * Created by webrx on 2017/6/30.
 */
public class BookServiceImp implements BookService {
    private BookMapper bookdao;
    private SqlSession session;
    public BookServiceImp(){
       this.session =new MybatisUtil().getSession();
       this.bookdao=session.getMapper(BookMapper.class);
    }

    public List<Book> queryAll() {
        List<Book> bk = this.bookdao.queryAll();
        this.session.commit();
        return bk;
    }

    public int deleteById(int id) {
        int n =this.bookdao.deleteById(id);
        this.session.commit();
        return n;
    }

    public int add(Book book) {
        int n = this.bookdao.add(book);
        this.session.commit();
        return n;
    }

    public int addMap(Map<String, Object> map) {
        int n =this.bookdao.addMap(map);
        this.session.commit();
        return n;
    }

    public int updateById(Map<String, Object> map) {
        int n =this.bookdao.updateById(map);
        this.session.commit();
        return n;
    }

    public Book queryById(int id) {
        Book book =bookdao.queryById(id);
        this.session.commit();
        return book;
    }

    public List<Book> page(Map<String, Integer> map) {
        List<Book> list =bookdao.page(map);
        return list;
    }
}
